package com.springcloud.configclient.consumer80.controller;

import com.springcloud.configclient.consumer80.lb.LoadBalancer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    public static final String INVOKE = "http://cloud-provider-payment";
    @Autowired
    private RestTemplate restTemplate;



    @GetMapping(value = "/consumer/payment/zk")
    public String paymnent() {

        return restTemplate.getForObject(INVOKE + "/payment/zk", String.class);
    }
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private LoadBalancer loadBalancer;
    //自己写的负载均衡
    /*@GetMapping(value = "/consumer1/payment/zk")
    public String getlb() {
        List<ServiceInstance> instances = discoveryClient.getInstances("cloud-provider-payment");
        ServiceInstance serviceInstance = loadBalancer.serviceInstance(instances);
        URI uri = serviceInstance.getUri();
        return restTemplate.getForObject(uri + "/payment/zk", String.class);

    }*/


}
